package bb

import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.TextUtils
import com.bumptech.glide.Glide
import com.clean.scanlibrary.bean.DiscernInfoBean
import oa.lla.cca.databinding.ActivityBodyScanBinding

class CE : AppCompatActivity() {

    private var dataBindF : ActivityBodyScanBinding? = null
    private val dataBind get() = dataBindF!!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        dataBindF = ActivityBodyScanBinding.inflate(layoutInflater)
        setContentView(dataBindF?.root)
        initView()

    }

    /**
     * [DiscernInfoBean(score=0.698742, name=null, root=商品-服装, keyword=夹克, baike_info=BaikeInfo(baike_url=null, image_url=null, description=null)), DiscernInfoBean(score=0.5232, name=null, root=非自然图像-屏幕截图, keyword=屏幕截图, baike_info=null), DiscernInfoBean(score=0.304124, name=null, root=商品-电脑办公, keyword=显示器屏幕, baike_info=null), DiscernInfoBean(score=0.154691, name=null, root=商品-电脑办公, keyword=书本, baike_info=null), DiscernInfoBean(score=0.006861, name=null, root=商品-鞋子, keyword=皮鞋, baike_info=null)]

     */


    companion object{
        val SCAN_INFO = "scanInfo"
        val IMAGE_URL = "imageUrl"

        fun startBodyScanActivity(context: Context,dataList:ArrayList<DiscernInfoBean>,url:String){
            val intent = Intent(context,CE::class.java)
            intent.putExtra(SCAN_INFO,dataList)
            intent.putExtra(IMAGE_URL,url)
            context.startActivity(intent)
            (context as Activity).finish()
        }
    }


    private fun initView() {

        val dataList:ArrayList<DiscernInfoBean> = intent.getSerializableExtra(SCAN_INFO) as ArrayList<DiscernInfoBean>

        val path = intent.getStringExtra(IMAGE_URL)
        Glide.with(this).load(path).into(dataBind.bodyImg)

        val sb:java.lang.StringBuilder = StringBuilder()

        for (item in dataList){
            if (!TextUtils.isEmpty(item.root)){
                sb.append("识别标签："+item.root+"\n")
                sb.append("识别物体："+item.keyword+"\n\n")
            }
        }


        if (!TextUtils.isEmpty(sb.toString())){
            dataBind.bodyScanText.text = sb.toString()
        }else{
            dataBind.bodyScanText.text = "暂无识别到相关标签与物体信息"
        }


        dataBind.bodyBack.setOnClickListener {
            finish()
        }



    }


}